package com.sys.db.action;


import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sys.db.manager.UserInfoManager;
import com.sys.pojo.UserInfo;

public class LoginAction extends ActionSupport {
	private String userName;
	private String password;
	private UserInfoManager userInfoManager;
	private static final long serialVersionUID = 1L;
	private String message;
	private boolean success; 
	/**
	 * 登陆
	 * @return
	 */
	public String login(){
		try {
			UserInfo info = userInfoManager.findByUserName(userName);
			if(info!=null){
				if(info.getUserPwd().equals(password)){
					ActionContext.getContext().getSession().put("userInfo", info);
					success=true;
				}else{
					message="密码错误！";
				}
			}else{
				message="该用户不存在！";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	@JSON(serialize=false)
	public UserInfoManager getUserInfoManager() {
		return userInfoManager;
	}

	public void setUserInfoManager(UserInfoManager userInfoManager) {
		this.userInfoManager = userInfoManager;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}
	
}
